﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test_ApplicationBD
{
    public class Music
    {
        private int m_ID;

        public int ID
        {
            get { return m_ID; }
            set { m_ID = value; }
        }
        private string m_nom;

        public string Nom
        {
            get { return m_nom; }
            set {
                m_nom = value;
                Commandehelper.RequeteComplexe("update Musique set Nom='" + Nom + "' where ID=" + ID + ";");
            
            }
        }

        private int m_longueur;

        public int Longueur
        {
            get { return m_longueur; }
            set {
                m_longueur = value;
                Commandehelper.RequeteComplexe("update Musique set Longeur='" + Longueur + "' where ID=" + ID + ";");
            }
        }
        public Music()
        {
            m_nom = "";
            m_longueur = 0;
        }
        public void ChargerMusic(int pID)
        {
            m_ID = pID;
            List<object[]> objcol = Commandehelper.RequeteComplexe("select * from Musique where ID= " + pID + ";");
            m_nom = objcol[0][1].ToString();
            m_longueur = (int)objcol[0][2];

        }

        public static Music CreateMusic(string pNom, int Longueur)
        {
            Music objMusic = new Music();
            objMusic.Nom = pNom;
            objMusic.Longueur = Longueur;
            Commandehelper.RequeteComplexe("insert into Musique (Nom, Longeur) values ('" + pNom + "', '" + Longueur + "');");
            return objMusic;
        }

        public static Music GetMusicByID(int pID)
        {

            Music objMus = new Music();
            List<object[]> coltabObj = Commandehelper.RequeteComplexe("select * from Musique Where ID=" + pID + ";");
            if (coltabObj == null)
                return null;

            objMus.ID = int.Parse(coltabObj[0][0].ToString());
            objMus.Nom = coltabObj[0][1].ToString();
            objMus.Longueur = int.Parse(coltabObj[0][2].ToString());
            return objMus;
        }

    }
}
